package com.wq.biz;

import com.wq.ui.coms.BasicMoveLabel;
import com.wq.ui.coms.ImageGet;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 飞机控制类
 *
 * @author wq
 * 2020/12/19 - 17:43
 */
public class Plane extends BasicMoveLabel {
    private int master, index;

    private int nextLen;

    private int len = -1;
//	private int special;
//	private int skip;

    private boolean canMove;

    public Plane(Icon icon) {
        super(icon);
    }

    public void iniConstruc(Icon icon, int master, int index) {
        this.setIcon(icon);
        this.master = master;
        this.index = index;
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                if (canMove) {
                    Manager.getManager().hasClickPlane(Plane.this);
                }
            }
        });
    }

    public int getMaster() {
        return master;
    }

    public int getIndex() {
        return index;
    }

    public void setMaster(int master) {
        this.master = master;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getLen() {
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public void addLen(int len) {
//		if(this.getLen() == ChessPane.OVER_LEN)
//		{
//			this.over();
//		}
        this.len += len;
    }

    public void over() {
//		setIcon(icon);
    }

//	public boolean isOver()
//	{
//		return isOver;
//	}


    public boolean isCanMove() {
        return canMove;
    }

    public void setCanMove(boolean canMove) {
        this.canMove = canMove;
        if (canMove) {
            this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        } else {
            this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    }

    public void reset(Plane thePlane) {
        len = -1;
        new Thread() {
            public void run() {
                while (true) {
                    if (thePlane.moveIsOver()) {
                        Plane.this.setNextPosition(ChessPane.getChessPane().getHomePoint(Plane.this.getMaster(), Plane.this.getIndex()));
                        return;
                    }
                }
            }
        }.start();
        System.out.println(" reset(Plane thePlane)" + master);
    }

    public void isOver() {//CHANGE
        new Thread() {
            public void run() {
                while (true) {
                    if (moveIsOver()) {
                        setIcon(ImageGet.getImageGet().getOverIcon());
                    }
                }
            }
        }.start();
    }

}
